//
//  EXUserSettingManager.m
//  Exercise
//
//  Created by 羊谦 on 16/5/31.
//  Copyright © 2016年 NetEase-yangqian. All rights reserved.
//

#import "EXUserSettingManager.h"

#define kUserSettingUserToken                 @"kUserSettingUserToken"

@interface EXUserSettingManager()
{
@private
    NSString    *_userTokenCache;//用户逻辑服务器的token
}
@end

@implementation EXUserSettingManager

+(EXUserSettingManager *)userSetting{
    static dispatch_once_t pred;
    static EXUserSettingManager    *__exUserSetting = nil;
    
    dispatch_once(&pred, ^{
        __exUserSetting = [[EXUserSettingManager alloc] init];
    });
    return __exUserSetting;
}

#pragma mark - 用户token
- (void)setUserToken:(NSString *)userToken
{
    _userTokenCache = userToken;
    
    if (_userTokenCache) {
        
        [[NSUserDefaults standardUserDefaults] setObject:_userTokenCache forKey:kUserSettingUserToken];
    } else {
        [[NSUserDefaults standardUserDefaults] setObject:nil forKey:kUserSettingUserToken];
    }
    
    [[NSUserDefaults standardUserDefaults] synchronize];
}

- (NSString *)userToken
{
    if (!_userTokenCache) {
        NSString *userToken = [[NSUserDefaults standardUserDefaults] stringForKey:kUserSettingUserToken];
        
        if (userToken) {
            _userTokenCache = userToken;
        }
    }
    
    return _userTokenCache;
}


@end
